package com.potenza.training.dictionary.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.dictionary.dao.ProjectEnvironmentDao;
import com.potenza.training.dictionary.entity.ProjectEnvironment;
import com.potenza.training.dictionary.server.ProjectEnvironmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("projectEnvironmentServiceImpl")
public class ProjectEnvironmentServiceImpl extends ServiceImpl<ProjectEnvironmentDao, ProjectEnvironment> implements ProjectEnvironmentService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ProjectEnvironmentDao projectEnvironmentDao;

    @Override
    public List<ProjectEnvironment> findAll() {
        Object projectEnvironment = redisTemplate.opsForValue().get("projectEnvironment");
        if (projectEnvironment==null){
            List<ProjectEnvironment> list = this.list();
            redisTemplate.opsForValue().set("projectEnvironment", list);
            return list;
        }

        return (List<ProjectEnvironment>)projectEnvironment;
    }

}